﻿
using System;

namespace Recept.Command
{
    /// -------------------------------------------------------------------------------------------
    /// <summary>
    /// Implementation of the action command infrastructure
    /// </summary>
    /// -------------------------------------------------------------------------------------------
    public sealed class ActionCommand : ActionCommandBase
    {
        // -- Members -----------------------------------------------------------------------------
        private Action action;

        
        /// ---------------------------------------------------------------------------------------
        /// <summary>
        /// Gets or sets the delegate to the method to execute
        /// </summary>
        /// ---------------------------------------------------------------------------------------
        public Action ActionHandler
        {
            get
            {
                return this.action;
            }

            set
            {
                this.action = value;
            }
        }

        /// ---------------------------------------------------------------------------------------
        /// <summary>
        /// This method is called to execute a command
        /// </summary>
        /// ---------------------------------------------------------------------------------------
        /// <param name="parameter">
        /// Optional parameter of the command
        /// </param>
        /// ---------------------------------------------------------------------------------------
        public override void Execute(object parameter)
        {
            if (this.action != null)
            {
                this.action();
            }
        }

        /// ---------------------------------------------------------------------------------------
        /// <summary>
        /// This method is called to execute a command
        /// </summary>
        /// ---------------------------------------------------------------------------------------
        public void Execute()
        {
            if (this.action != null)
            {
                this.action();
            }
        }
    }
}
